package indi.jp.project.business.jingying.controller;

import indi.jp.project.business.jingying.pojo.po.ProjectTrackPO;
import indi.jp.project.business.jingying.pojo.po.ProjectTrackRecordPO;
import indi.jp.project.business.jingying.pojo.query.ProjectTrackQuery;
import indi.jp.project.business.jingying.pojo.query.ProjectTrackRecordQuery;
import indi.jp.project.business.jingying.service.ProjectTrackService;
import indi.jp.project.core.entity.JsonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 项目跟踪
 *
 * @author jiangping
 * @date 2022/6/5
 */
@RestController
@RequestMapping("/jingying/project/track")
public class ProjectTrackController {

    @Resource
    private ProjectTrackService projectTrackService;

    @GetMapping("/grid")
    public JsonResult queryGrid(ProjectTrackQuery query) throws Exception {
        return projectTrackService.queryGrid(query);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody ProjectTrackPO projectTrackPO, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        projectTrackPO.setCreateBy(account);
        projectTrackPO.setModifyBy(account);
        return projectTrackService.save(projectTrackPO);
    }

    @GetMapping("/find")
    public JsonResult findById(@RequestParam String id) throws Exception {
        return projectTrackService.findById(id);
    }

    @PostMapping("/delete")
    public JsonResult deleteById(@RequestParam String id) throws Exception {
        return projectTrackService.deleteById(id);
    }

    @GetMapping("/record_grid")
    public JsonResult queryRecordGrid(ProjectTrackRecordQuery query) throws Exception {
        return projectTrackService.queryRecordGrid(query);
    }

    @PostMapping("/record_save")
    public JsonResult saveRecord(@RequestBody ProjectTrackRecordPO projectTrackRecordPO, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        projectTrackRecordPO.setCreateBy(account);
        projectTrackRecordPO.setModifyBy(account);
        return projectTrackService.saveRecord(projectTrackRecordPO);
    }

    @PostMapping("/record_delete")
    public JsonResult deleteRecord(@RequestParam String id) throws Exception {
        return projectTrackService.deleteRecord(id);
    }
}
